package com.bootdo.system.config;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BDSessionListener implements SessionListener {

    private final AtomicInteger sessionCount = new AtomicInteger(0);
    Logger logger = LoggerFactory.getLogger(BDSessionListener.class);

    @Override
    public void onStart(Session session) {
        sessionCount.incrementAndGet();
        //有访问时触发
        logger.info("onStart访问人员个数为：" + sessionCount.get());
    }

    @Override
    public void onStop(Session session) {
        sessionCount.decrementAndGet();
        //主动退出时触发
        logger.info("onStop当前登陆人员个数为：" + sessionCount.get());

    }

    /**
     * 超时触发
     */
    @Override
    public void onExpiration(Session session) {

        sessionCount.decrementAndGet();

    }

    public int getSessionCount() {
        return sessionCount.get();
    }

}
